﻿#include "AgreementController.h"
#include "IndexWindow.h"

AgreementController::AgreementController(){}

AgreementController::~AgreementController(){}

void AgreementController::viewDidLoad(){
	CAView* view=this->getView();
	CAView* subview=CAView::createWithLayout(DLayout(DHorizontalLayoutFill, DVerticalLayout_T_H(0, 100)), themeColor);
	CAButton* btn=CAButton::create(CAButton::Type::Custom);
	btn->setZOrder(100);
	btn->setLayout(DLayout(DHorizontalLayout_L_W(10, 64), DVerticalLayout_H_C(64, 0.5)));
	btn->setImageForState(CAControl::State::Normal, CAImage::create("layout/btn_left_white.png"));
	btn->addTarget([=]{
		web=nullptr;
		this->dismissModalViewController(true);
	}, CAButton::Event::TouchDown);
	subview->addSubview(btn);
	CALabel* title=CALabel::createWithLayout(DLayout(DHorizontalLayoutFill, DVerticalLayout_H_C(50, 0.5)));
	title->setText("用户协议");
	title->setFontSize(40);
	title->setColor(CAColor4B::WHITE);
	title->setTextAlignment(CATextAlignment::Center);
	title->setVerticalTextAlignmet(CAVerticalTextAlignment::Center);
	subview->addSubview(title);
	view->addSubview(subview);

	web=CAWebView::createWithLayout(DLayout(DHorizontalLayoutFill, DVerticalLayout_T_H(100, 500)));
	web->loadFile("html/iceEditor.html");
	web->setVisible(false);
	web->showLoadingActivity(true);
	web->setJavascriptInterfaceScheme("j2c");
	web->onFinishLoading([&](const string& msg){
		web->showLoadingActivity(false);
		web->evaluateJS("setMsg('<p>测试初始化赋值1</p>')");
	});
	web->onJSCallback([&](const std::string& msg){
		web->evaluateJS("alert('"+msg.substr(4)+"')");
	});
	view->addSubview(web);

	btn=CAButton::createWithLayout(DLayout(DHorizontalLayout_W_C(300, 0.5), DVerticalLayout_H_C(90, 0.8)), CAButton::Type::RoundedRect);
	btn->setTitleForState(CAControl::State::Normal, "获取输入内容");
	btn->setTitleFontSize(40);
	btn->addTarget([=]{
		web->evaluateJS("getMsg()");
	}, CAButton::Event::TouchDown);
	view->addSubview(btn);
}